import {CanActivate, Router} from "@angular/router";
import {Injectable} from "@angular/core";
import {User} from "../model/user";
/**
 * Created by jike on 2017/6/5.
 */
@Injectable()
export class LoginGuard implements CanActivate{

  public currentUser: User;

  constructor(public routerInfo: Router){
  }

  canActivate() {
    let logined:boolean = true;
    this.currentUser = JSON.parse(sessionStorage.getItem("currentUser"));
    console.log(this.currentUser);
    if(this.currentUser==null){
      console.log("用户未登录");
      this.routerInfo.navigateByUrl('/login');
    }else {
      logined =true;
      console.log("用户已登录");
    }
    return logined;
  }

}

